package articles_api

import (
	"gin_study_blog/common"
	"gin_study_blog/common/http"
	"gin_study_blog/models"
	"gin_study_blog/service/redis"
	"gin_study_blog/utils"
	"github.com/gin-gonic/gin"
)

func (ArticlesApi) ArticleViewDetail(c *gin.Context) {
	var cr models.EsIDRequest
	err := c.ShouldBindUri(&cr)
	if err != nil {
		http.FailWithCode(http.ParamsError, c)
		return
	}
	err = redis.NewArticleLook().Set(cr.ID)
	if err != nil {
		common.Log.Error(err)
		http.FailWithMessage(err.Error(), c)
		return
	}
	res, err := utils.CommDetail(cr.ID)
	if err != nil {
		common.Log.Error(err)
		http.FailWithMessage("文章不存在", c)
		return
	}
	http.IsOkWithData(res, c)
}
